//某些时间计算的函数与变量
var day2sec = 1*24*60*60;
var hour2sec = 60*60;
var min2sec = 60;

//将时间转换为秒
function time2sec(days, hours, minutes, seconds){
    let res = 0;
    if(days != null && days != 0){
        res += days * day2sec;
    }

    if(hours != null && hours != 0){
        res += hours * hour2sec;
    }

    if(minutes != null && minutes != 0){
        res += days * day2sec;
    }

    if(seconds != null && seconds != 0){
        res += seconds;
    }

    return res;
}

//days天后的凌晨
function days2sec(days){
    let date = new Date(new Date().toLocaleDateString()); //今天凌晨
    date.setTime(date.getTime() + days*day2sec*1000);
    return date.getTime()/1000;
}

//时间戳转时间，精确到分钟
function sec2time(sec){
    
    if(sec <= 0){
        return 0;
    }

    if(sec <= 60){
        return "1分钟";
    }

    let res = "";

    let overDay = 0;
    let overHour = 0;

    if(sec >= day2sec){
        let days = parseInt(sec / day2sec);
        res += days + "天";
        sec %= day2sec;
        overDay = 1;
    }

    if(overDay == 1 || sec >= hour2sec){
        let hours = parseInt(sec / hour2sec);
        if(overDay == 1){
            res += " ";
        }
        res += hours + "小时";
        sec %= hour2sec;
        overHour = 1;
    }

    if(overHour == 1 || sec >= min2sec){
        let min = parseInt(sec / min2sec);
        if(overHour == 1){
            res += " ";
        }
        res += " " + min + "分钟";
    }
    
    return res;
}

//获取当前时间戳
function getTimestamp(){
    return parseInt(new Date().getTime() / 1000);
}